<?php
/**
 * Created by PhpStorm.
 * User: as
 * Date: 2018/10/21
 * Time: 23:49
 */

namespace app\admin\model;


use think\Model;
use traits\model\SoftDelete;

class Coupon extends Model
{
    use SoftDelete;
    protected $autoWriteTimestamp = true;
    protected $createTime = 'add_time';
    protected $field = true;

    public function getStartTimeAttr($val)
    {
        return date('Y-m-d H:i:s',$val);
    }
    public function getEndTimeAttr($val)
    {
        return date('Y-m-d H:i:s',$val);
    }
    public function getCouponTypeAttr($name)
    {
        switch ($name){
            case '1':
                return array('type' => $name,'type_msg' => '元');
                break;
            default:
                return array('type' => $name,'type_msg' => '折');
                break;
        }
    }
    public function getCouponRuleAttr($name)
    {
       $val = explode(',', $name);
        switch ($val[0]){
            case '1':
                return array('rule_msg'=>'满'.$val[1].'元','type_id'=>$val[0]);
                break;
            case '2':
                $type_name = GoodsType::where('type_id','=',$val[1])->find();
                return array('rule_msg'=>'只是 '.$type_name['type_name'].' 系列商品','type_id'=>$val[0]);
                break;
            case '3':
                $type_name = GoodsType::where('type_id','=',$val[1])->find();
                return array('rule_msg'=>'不含 '.$type_name['type_name'].' 系列商品','type_id'=>$val[0]);
                break;
            case '4':
                $type_name = GoodsType::where('type_id','=',$val[1])->find();
                return array('rule_msg'=>'含 '.$type_name['type_name'].' 系列商品','type_id'=>$val[0]);
                break;
            default:
                return array('rule_msg'=>'任何情况下','type_id'=>$val[0]);
                break;
        }
//        return $val;
    }
}